package com.wfm.niuke;

import org.junit.Test;

public class BeautySum1781 {
    public int beautySum(String s){
        int res = 0;
        char[] chars = s.toCharArray();
        for (int i = 0; i <= chars.length-3; i++) {
            for (int j = i+2; j <= chars.length-1; j++) {
                String substring = s.substring(i, j+1);
                res+= getValue(substring);
            }
        }
        return res;
    }
    public int getValue(String s){
        int[] cnt = new int[26];
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            cnt[c - 97]++;
        }
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < cnt.length; i++) {
            if(cnt[i]!=0){
                min = Math.min(cnt[i], min);
                max = Math.max(cnt[i], max);
            }
        }
        return max-min;
    }
    @Test
    public void test(){
        System.out.println(beautySum("aabcbaa"));
    }
}
